# The next line is used to include the current developing tkMD into tcl package search path. Wouldn't be needed for deploy.
set auto_path [concat [pwd]/../../pkg/tkMD $auto_path ]
## A example program of using 
#\verbatim

package require tkMD 1.1
namespace import SimTask::*

## setup the simulation environment
set SimTask::PdbPath [pwd]/../pdb
set SimTask::TemplatePath [pwd]/template
set SimTask::JobPath [pwd]/job
set SimTask::RunPath [pwd]/run1
set SimTask::Njobs 5

#set SimTask::Charmmbin /media/data/yi/simulation/software/mbuilder/bin/c37a1
#set SimTask::Charmmbin /usr/local/bin/charmm
printEnv

## setup the parameters for simulations.
set peptides { 2mag 2mlt 1f0d 1f0e 1f0f 1f0g 1f0h }
set type { water neutral anionic}
set temp 298
set thick 26
set ionc 0.1
set anfr 0.3
set preptime 0.01
set eqltime 0.02
set orientation { o0 }

## The parameters can contain multiple possible values( such as type ).
## Combinations will be made for all variables. 
## Dependent parameters can also be parsed from expressions containing variables that the values are uncertain at this point.

## for example, define:
proc differentTime { type } {
   switch $type {
       water { return 0.2 }
       default { return 0.1 }
   }
}

## Then, 
set eqltime { [ differentTime @type ] }
## Notice that {} is used to protect differentTime from execuation at definition time. @type will be replaced by the variable type later. 
## array can also be used to create dependent parameters. For example:
array set ThickTable { dopc 27 dmpc 23.5 dlpc 19.5 }
## then define thick:
set membrane {dlpc dmpc}
set thick @ThickTable(@membrane)
# Then, if membrane is dlpc, the variable thick is 23.5.
# But remember: membrane, thick, ThickTable must all be in the VarSpace

## Add the parameters that will be passed to CHARMM into a VarSpace called options that can be passed to simulator.
Path::VarSpace options { type temp thick ionc anfr orientation preptime eqltime  membrane ThickTable }

## print some information for logging.
set timestamp [clock format [clock seconds] -format "%b %d %y - %T"]
puts "Start Simulation with { $argv0 $argv } @ $timestamp "
puts "==============================================================="
printEnv
puts "==============================================================="
puts "Peptides to be simulated:"
puts "==============================================================="
puts "$peptides"
puts "==============================================================="
puts "Parameters will be using for the simulations: "
puts "==============================================================="
Path::printVarSpace options
puts "==============================================================="


## do the simulation for each peptide 
foreach peptide $peptides {

    set timestamp [clock format [clock seconds] -format "%b %d %y - %T"]
    puts "Prepare: $peptide , Current time: $timestamp "
    puts "==============================================================="

    prepfiles $peptide {o0.crd o1.crd o2.crd o3.crd o4.crd pept.psf}
    run 4 $peptide run.inp options --combinejob run orientation --skip { file exists eql_min.crd } --post { }
}
waitfor run

## clean up, remove all the output files to save disk space.
rmfiles $SimTask::RunPath  *.out

#\endverbatim
